package com.learn.base;

public class DemoThreadLock {


    public static void main(String[] args) {
        /*SendMoneyLock sendMoneyThread = new SendMoneyLock();
        new Thread(){
            @Override
            public void run() {
                sendMoneyThread.sendMoney(1,10,this.getName());
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                sendMoneyThread.sendMoney(2,20,this.getName());
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                sendMoneyThread.sendMoney(3,70,this.getName());
            }
        }.start();

        try {
            Thread.sleep(1000);
            System.out.println("最后账户="+sendMoneyThread.getAccout());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        SendMoneySynchronized sendMoneyThread = new SendMoneySynchronized();
        new Thread(){
            @Override
            public void run() {
                sendMoneyThread.sendMoney(1,10,this.getName());
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                sendMoneyThread.sendMoney(2,20,this.getName());
            }
        }.start();

        new Thread(){
            @Override
            public void run() {
                sendMoneyThread.sendMoney(3,70,this.getName());
            }
        }.start();

        try {
            Thread.sleep(1000);
            System.out.println("最后账户="+sendMoneyThread.getAccout());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }



}
